#include <interfacelib/window/Caret.h>
#include <interfacelib/window/window.h>
#include <interfacelib/directx/synchronized_dx.h>
#include <interfacelib/directx/initd3d.h>

using namespace interfacelib::Window;

Caret::Caret() : m_CaretType( WINDOW_CARET_NORMAL ), m_parentWindow( NULL ), 	m_currentLineYPos( 0 )
{
}

void Caret::initialize()
{
	m_stringPos = 0;
}

Caret::~Caret()
{
}

BYTE Caret::draw( RECT *rect )
{
	if ( !m_parentWindow ) return ( 0xFF );
	
	if ( ( DWORD )rect->right > m_parentWindow->getWidth() ) return ( ERROR_DRAWCARET_OVERSIDE_WINDOW );

	if ( ( GetTickCount() % 1000 ) < CARET_BLINK_TIME ) return ( 0xFF );

	POINT point;

	m_parentWindow->getWindowPos( &point );

	rect->left +=  point.x;
	rect->top += point.y + m_currentLineYPos;
	rect->right += point.x;
	rect->bottom += point.y + m_currentLineYPos;

	Box::draw( rect );

	return ( 0 );
}